package org.ljy.rabbitextensionsdemo.listener;

import com.rabbitmq.client.Channel;
import org.ljy.rabbitextensionsdemo.constant.Constant;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

@Component
public class QosListener {

    @RabbitListener(queues = Constant.QOS_QUEUE)
    public void qosListener(Message message, Channel channel) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
            System.out.println("消费："+new String(message.getBody()));
            channel.basicAck(deliveryTag, false); //不进行消息确认
        }catch (Exception e){
            channel.basicNack(deliveryTag, false, false);
        }
    }
}
